package y24.m5;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

class Student{
    private String ID;
    private String name;
    private Byte sex;
    private Date birthday;
    private String home;
    private Double result;
}

public class StudentData {

    static class Frame extends JFrame {
        private JButton submitButton;
        private JLabel[] label;
        private JTextField[] textFields;
        private JTextArea student;

        public Frame(){
            JPanel inputPanel = new JPanel(new GridLayout(6, 2));
            student = new JTextArea(12,34);
            insertPanel(inputPanel);//录入学生信息
            this.submitButton = new JButton("提交");
            submitButton.setPreferredSize(new Dimension(30,30));
            submitButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    updateStudent();
                }
            });

            setLayout(new BorderLayout());
            add(inputPanel,BorderLayout.NORTH);
            add(submitButton,BorderLayout.CENTER);
            add(student,BorderLayout.SOUTH);

            setLocationRelativeTo(null);
            setSize(600, 400);
            setBackground(Color.CYAN);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setTitle("学生信息录入");
            setVisible(true);

        }
        private void updateStudent(){
            StringBuffer str = new StringBuffer();
            for (int i = 0; i < 6; i++) {
                str.append(label[i].getText());

                str.append(textFields[i].getText());
                str.append('\n');
            }

            student.setText(String.valueOf(str));

        }

        private void insertPanel(JPanel inputPanel) {
            this.label = new JLabel[6];
            this.textFields = new JTextField[6];
            this.label[0] = new JLabel("ID:");
            this.textFields[0]  = new JTextField(10);
            this.label[1] = new JLabel("name:");
            this.textFields[1]  = new JTextField(5);
            this.label[2] = new JLabel("sex:");
            this.textFields[2]  = new JTextField(1);
            this.label[3] = new JLabel("birthday:");
            this.textFields[3]  = new JTextField(10);
            this.label[4] = new JLabel("home:");
            this.textFields[4]  = new JTextField(10);
            this.label[5] = new JLabel("result:");
            this.textFields[5]  = new JTextField(10);
            for (int i = 0; i < 6; i++) {
                inputPanel.add(this.label[i]);
                inputPanel.add(this.textFields[i]);
            }
        }

    }

    public static void main(String[] args) {
        new Frame();
    }
}

